//dojo.require("dojo.widget.Editor");
dojo.require("junc.effect.Size");


junc.log.setDebugEnable(false);
var log = new junc.log.Log("moo.findThread");
// {{ search pane element
var search_option = null;
var search_pane = null;
var resize_search_handle = null;
// }}
// {{ thread pane element
var thread_pane = null;
var show_thread_pane = null;
var edit_pane = null;
var resize_edit_handle = null;
var edit_content_pane = null;
var resize_edit_handle_opened = false;
var resize_edit_handle_moving = false;	
// }}
var myrules = {
	'body':function(e) {
		search_pane = $("search_pane");
		search_option = $("search_option");
		resize_search_handle = $("resize_search_handle");
		thread_pane = $("thread_pane");
		show_thread_pane = $("show_thread_pane");
		edit_pane = $("edit_pane");
		resize_edit_handle = $("resize_edit_handle");
		edit_content_pane = $("edit_content_pane");
		log.debug(junc.lang.detailType(show_thread_pane));
		log.debug(junc.lang.detailType(edit_pane));
		log.debug(junc.lang.detailType(resize_edit_handle));
		log.debug(junc.lang.detailType(edit_content_pane));
	},
	
	'#category_options a':function(e) {
		e.onclick=function() {
			alert(this.innerHTML);
		}
	},


	'#resize_edit_handle' : function(ele) {
		ele.onclick = function() {
			if(false == resize_edit_handle_moving) {
				resize_edit_handle_moving = true;
				if (resize_edit_handle_opened) {
					edit_content_pane.style.display = "none";
					edit_pane.style.height = "18px";
					new junc.effect.Size(
						show_thread_pane,
						null,
						562,  
						5,
						10,
						{
							complete:function(){
								resize_edit_handle.className = "handle handle-up handle-close";
								resize_edit_handle_opened = false;	
								resize_edit_handle_moving = false;		
							}
						}  
					);
				} else {
					new junc.effect.Size(
						show_thread_pane,
						null,
						380,
						5, 
						10, 
						{
							complete:function(){
								//alert(edit_pane.offsetHeight);
								edit_pane.style.height =  "200px";
								edit_content_pane.style.display = "block";
								resize_edit_handle.className = "handle handle-down handle-open";
								resize_edit_handle_opened = true;
								resize_edit_handle_moving = false;										
							}
						} 
					);
				}
			}				
		}
	},
		
	'#resize_search_handle' : function(ele) {
		//indicate search_pane status
		resize_search_handle._opened = true;
		//indicate pane is resizing... 
		resize_search_handle._moving = false;	
		resize_search_handle._default_class = resize_search_handle.className;
		resize_search_handle._default_search_width = search_pane.offsetWidth;
		resize_search_handle._default_thread_width = thread_pane.offsetWidth;	
		ele.onclick = function() {
			if(false == resize_search_handle._moving) {
				resize_search_handle._moving = true;
				if (resize_search_handle._opened) {
					search_option.style.display = "none";
					search_pane.style.width = resize_search_handle.offsetWidth + "px";
					new junc.effect.Size(
						thread_pane,
						resize_search_handle._default_search_width 
									+ resize_search_handle._default_thread_width - search_pane.offsetWidth,  
						null,
						5,
						7,
						{
							complete:function(){
								//thread_pane.style.width = resize_search_handle._default_search_width + resize_search_handle._default_thread_width - resize_search_handle._close_width + "px";
								resize_search_handle.className = "handle handle-left handle-close";
								resize_search_handle._opened = false;	
								resize_search_handle._moving = false;		
								//alert(resize_search_handle.offsetWidth);
							}
						}  
					);
				} else {
					new junc.effect.Size(
						thread_pane, 
						resize_search_handle._default_thread_width, 
						null, 
						5, 
						7, 
						{
							complete:function(){
								search_pane.style.width = resize_search_handle._default_search_width +"px";
								//error: property offsetWidth only has getter
								//search_pane.offsetWidth = resize_search_handle._default_search_width;
								search_option.style.display = "block";
								resize_search_handle.className = resize_search_handle._default_class;
								//resize_search_handle.style.backgroundImage = "url(" + ICO_LOC + "triangle_right.gif)";
								resize_search_handle._opened = true;
								resize_search_handle._moving = false;										
							}
						} 
					);
				}
			}				
		}
	}
};
junc.dom.Behaviour.register(myrules);
// }}

